/**
 * autho Huahua
 * @param date
 * @returns {String}
 */
var websocket="";
function formatdate(date) {
	var newdate = new Date(date);
	var year = newdate.getFullYear();
	var month = (newdate.getMonth()+1).toString();
	var day = (newdate.getDate()).toString();
	var hour = (newdate.getHours()).toString();
	var min = (newdate.getMinutes()).toString();
	var sec = (newdate.getSeconds()).toString();
	if(month.length == 1){
		month = "0"+month;
	}
	if(day.length == 1){
		day = "0" + day;
	}
	if(hour.length == 1){
		hour = "0" + hour;
	}
	if(min.length == 1){
		min = "0" + min;
	}
	if(sec.length == 1){
		sec = "0" + sec;
	}
	var result = year+"-"+month+"-"+day+" "+hour+":"+min+":"+sec;
	return result;
	}



/**
 * autho Huahua
 * @param date
 * @returns {String}
 */
var websocket="";
function dayformatdate(date) {
	var newdate = new Date(date);
	var year = newdate.getFullYear();
	var month = (newdate.getMonth()+1).toString();
	var day = (newdate.getDate()).toString();
	
	if(month.length == 1){
		month = "0"+month;
	}
	if(day.length == 1){
		day = "0" + day;
	}
	
	var result = year+"-"+month+"-"+day;
	return result;
	}




/**
 * 快捷导航数据格式转换 
 * @param result
 * @returns {String}
 */
function formatQnav(result){
	 var qinfos = []; 
    for(var i=0;i<result.data.length;i++){
    	 var qinfo ={};
    	 var qid = result.data[i].id;
    	 var quserid = result.data[i].userid;
    	 var qname = result.data[i].name; 
    	 var qurl = result.data[i].url;
    	 var qpid = result.data[i].pid;
    	 var qstatus = result.data[i].status;
    	 qinfo.id = qid;
    	 qinfo.userid = quserid;
    	 qinfo.name = qname;
    	 qinfo.url = qurl;
    	 qinfo.pid = qpid;
    	 qinfo.status = qstatus;
    	 qinfos.push(qinfo);
    }
    return qinfos;
}


/**
 * 显示iframe页面
 * @param url
 */
function displayinfo(url){
	checkLogin(displayiFrameInfo,url);
}

/**
 * 显示iframe页面-菜单
 * @param url
 */
function displaymenuinfo(url){
	checkLogin(displayiFrameMenuInfo,url);
}

/**
 * 判断是否登录
 * @param funcName
 * @param param
 */

function checkLogin(funcName,param){
	/*$.ajax({
		  type: 'GET',
		  dataType:"json",
	      cache:false,
	      async:false,
		  url: "/palace/root.checkLogin.do",
		  error:function(){
			  //redirect
			  window.parent.location.href = "/palace";
		  },
		  success:function(result){
				  funcName(param);
		  }
	});*/
	 funcName(param);
}



/**
 * 显示iframe框架内容
 * @param url
 */
function displayiFrameInfo(url){
	$(window.parent.document).find("#iframe0").attr("src",url); 
}


/**
 * 显示iframe框架内容
 * @param url
 */
function displayiFrameMenuInfo(url){
  	$(window.parent.document).find("#iframe1").attr("src",url); 
}


/**
 * 显示兼职页面
 * @param url
 */
function displayJzPage(url){
	window.location.href = url;
}

/**
 * 显示其他业务系统页面
 * @param url
 */
function displayOtherPage(url){
	window.open(url);
}




/**
 * 
 * formatFileSize 功能：将给定的数据值格式化为易读的大小格式
 * @author Huahua
 * @param value： 要处理的数据大小
 * @param p：保留的小数位数
 * @returns {String}
 */
function formatFileSize(value,p) {  
	if(null==value||value==''){  
	    return "0B";  
	  }  
	  var unitArr = new Array("Bytes","KB","MB","GB","TB","PB","EB","ZB","YB");  
	  var index=0;  
	  
	  var srcsize = parseFloat(value);  
	  var quotient = srcsize;  
	  while(quotient>1024){  
	    index +=1;  
	   quotient=quotient/1024;  
	  }  
	  return roundFun(quotient,p)+" "+unitArr[index];  
}



/**
 * 
 * roundFun 功能：四舍五入保留小数位数
 * @author Huahua
 * @param numberRound:被处理的数
 * @param roundDigit:保留几位小数位 
 * @returns {Number}
 */
function  roundFun(numberRound,roundDigit)   //处理金额 -by hailang    
{     
 if(numberRound>=0) {    
	 var tempNumber = parseInt((numberRound*Math.pow(10,roundDigit)+0.5))/Math.pow(10,roundDigit);     
     return tempNumber;     
  }else{     
     numberRound1=-numberRound;     
     var tempNumber = parseInt((numberRound1*Math.pow(10,roundDigit)+0.5))/Math.pow(10,roundDigit);     
   return -tempNumber;     
  }     
}  

/**
 * 
 * pm25Formatter 功能：pm2.5 formatter
 * @author Huahua
 * @param pm25
 * @returns {String}
 */
function pm25Formatter(pm25){
	if(pm25>0 && pm25<=35){
		return "优";
	}else if(pm25>35 && pm25<=75){
		return "良";
	}else if(pm25>75 && pm25<=115){
		return "轻度污染";
	}else if(pm25>115 && pm25<=150){
		return "中度污染";
	}else if(pm25>150 && pm25<=250){
		return "重度污染";
	}else if(pm25>250 && pm25<=500){
		return "严重污染";
	}
}

/**
 * 
 * fxFormatter 功能：风向formatter
 * @author Huahua
 * @param fx
 * @returns {String}
 */
function fxFormatter(fx){
	if((fx>0 && fx<=11.25)||(fx>348.76 && fx<360)){
		return "北";
	}else if(fx>11.26 && fx<=33.75){
		return "北东北";
	}else if(fx>33.76 && fx<=56.25){
		return "东北";
	}else if(fx>56.26 && fx<=78.75){
		return "东东北";
	}else if(fx>78.76 && fx<=101.25){
		return "东";
	}else if(fx>101.26 && fx<=123.75){
		return "东东南";
	}else if(fx>123.76 && fx<=146.25){
		return "东南";
	}else if(fx>146.26 && fx<=168.75){
		return "南东南";
	}else if(fx>168.76 && fx<=191.25){
		return "南";
	}else if(fx>191.26 && fx<=213.75){
		return "南西南";
	}else if(fx>213.76 && fx<=236.25){
		return "西南";
	}else if(fx>236.26 && fx<=258.75){
		return "西西南";
	}else if(fx>258.76 && fx<=281.25){
		return "西";
	}else if(fx>281.26 && fx<=303.75){
		return "西西北";
	}else if(fx>303.76 && fx<=326.25){
		return "西北";
	}else if(fx>326.26 && fx<=348.75){
		return "北西北";
	}
}
/**
 * 
 * fsFormatter 功能：风速formatter
 * @author Huahua
 * @param fs
 * @returns {String}
 */
function fsFormatter(fs){
	if(fs>0 && fs<=0.2){
		return "0级";
	}else if(fs>0.3 && fs<=1.5){
		return "1级";
	}else if(fs>1.6 && fs<=3.3){
		return "2级";
	}else if(fs>3.4 && fs<=5.4){
		return "3级";
	}else if(fs>5.5 && fs<=7.9){
		return "4级";
	}else if(fs>8.0 && fs<=10.7){
		return "5级";
	}else if(fs>10.8 && fs<=13.8){
		return "6级";
	}else if(fs>13.9 && fs<=17.1){
		return "7级";
	}else if(fs>17.2 && fs<=20.7){
		return "8级";
	}else if(fs>20.8 && fs<=24.4){
		return "9级";
	}else if(fs>24.5 && fs<=28.4){
		return "10级";
	}else if(fs>28.5 && fs<=32.6){
		return "11级";
	}else if(fs>32.7 && fs<=36.9){
		return "12级";
	}else if(fs>37.0 && fs<=41.4){
		return "13级";
	}else if(fs>41.5 && fs<=46.1){
		return "14级";
	}else if(fs>46.2 && fs<=50.9){
		return "15级";
	}else if(fs>51.0 && fs<=56){
		return "16级";
	}else if(fs>=56.1){
		return "17级";
	}
}
/**
 * 
 * formatTdContent 功能：表格内容格式化和转义
 * @author Huahua
 * @param tdString
 * @returns {String}
 */
function formatTdContent(tdString){
	if(tdString.indexOf("<a") == -1){	//不包含样式	
		tdString = tdString.replace(/\"/g,"&quot;");		//真是恶心的转义get it!
		return '<span title="'+tdString+'" style="cursor:default">'+tdString+'</span>';
	}else{
		tdString = tdString.replace("#ffffff", "#000000");
		var tempString = tdString.split(">");
		var realString = (tempString[1].split("<"))[0];
		var realStringBefore = tempString[0]+" title='"+realString+"'>";
		var realStringAfter = "<"+ (tempString[1].toString().split("<"))[1]+">";
		return realStringBefore + realString + realStringAfter;
	}
}

/**
 * 任务名称格式化
 * @param tdString
 * @returns {String}
 */
function formatTaskName(tdString){
	if(tdString.indexOf("<a") == -1){	//不包含样式	
		tdString = tdString.replace(/\"/g,"&quot;");		//真是恶心的转义get it!
		return '<span title="'+tdString+'" style="cursor:default">'+tdString+'</span>';
	}else{
		var tempString = tdString.split(">");
		if(tempString.length == 3){	//a标签不包含img
			var realString = (tempString[1].split("<"))[0];
			var realStringBefore = tempString[0]+" title='"+realString+"'>";
			var realStringAfter = "<"+ (tempString[1].toString().split("<"))[1]+">";
			return realStringBefore + realString + realStringAfter;
		}else if(tempString.length == 4){	//a标签包含img
			var titleString = (tempString[2].split("<"))[0];
			var realString = tempString[1]+">"+(tempString[2].split("<"))[0];
			var realStringBefore = tempString[0]+" title='"+titleString+"'>";
			var realStringAfter = "<"+ (tempString[2].toString().split("<"))[1]+">";
			return realStringBefore + realString + realStringAfter;
		}
		
	}
}